package me.itsoo.artemis.framework.repository.exception;

import me.itsoo.artemis.framework.core.util.StringUtils;

import java.sql.SQLException;

/**
 * UncategorizedSqlException
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/18
 */
public class UncategorizedSqlException extends RuntimeException {

    private static final long serialVersionUID = 1281603470297065701L;

    public UncategorizedSqlException(String errorMsg) {
        super(errorMsg);
    }

    public UncategorizedSqlException(SQLException e) {
        this(getErrorMsg(e));
    }

    public static String getErrorMsg(SQLException e) {
        return StringUtils.format("[{}: {}] {}", e.getErrorCode(), e.getSQLState(), e.getMessage());
    }

    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}
